﻿using System;
using System.Windows;
using System.Windows.Shapes;
using System.Windows.Controls;
using System.Windows.Media;

namespace VirtualTileTest2 {
    class TileItem : IVirtualTile {
        private Rectangle mRect;
        private Image mImage;
        private Size mWH;
        private int mOrdinal;

        public TileItem(int ordinal, Size tileSize) {
            mOrdinal = ordinal;
            mWH = new Size(tileSize.Width,tileSize.Height);
        }

        public UIElement Visual {
            get {
                return mRect;
            }
        }

        /// <summary>
        /// Create the WPF visual for this object.
        /// </summary>
        /// <param name="parent">The canvas that is calling this method</param>
        /// <returns>The visual that can be displayed</returns>
        public UIElement CreateVisual(VirtualizingTilePanel2 parent) {
            if (null != mRect) {
                return mRect;
            }
            mRect = new Rectangle();
            mRect.Fill = Brushes.Aqua;
            mRect.Width = mWH.Width * 0.9;
            mRect.Height = mWH.Height * 0.9;

            Console.WriteLine("TileItem.CreateVisual {0}", mOrdinal);
            return mRect;
        }

        /// <summary>
        /// Dispose the WPF visual for this object.
        /// </summary>
        public void DisposeVisual() {
            mRect = null;
            mImage = null;
            Console.WriteLine("TileItem.DisposeVisual {0}", mOrdinal);
        }
    }
}
